//package com.sunlands.deskmate.controller;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.sunlands.deskmate.client.AuthClient;
//import com.sunlands.deskmate.client.UserCenterService;
//import com.sunlands.deskmate.dto.RequestDTO;
//import com.sunlands.deskmate.entity.TzChatRecord;
//import com.sunlands.deskmate.mapper.TzChatRecordMapper;
//import com.sunlands.deskmate.service.impl.MessageServiceImpl;
//import com.sunlands.deskmate.sstwds.ContentSecCheck;
//import com.sunlands.deskmate.vo.UsersVO;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//import java.util.concurrent.ConcurrentHashMap;
//import java.util.stream.Collectors;
//
///**
// * Created by yanliu on 2019/5/7.
// */
//
//@RestController
//@Slf4j
//@RequestMapping("/test")
//public class TestController {
//
//    @Autowired
//    private TzChatRecordMapper tzChatRecordMapper;
//
//    @Autowired
//    private ContentSecCheck contentSecCheck;
//    @Autowired
//    private MessageServiceImpl messageService;
//    @Autowired
//    private UserCenterService userCenterService;
//
//    @GetMapping("/test")
//    public String test111() {
//
//        Map<Long, UsersVO> userList = new ConcurrentHashMap<>();
//        List<TzChatRecord> all = messageService.findAll();
//        all = all.stream().filter(chatRecord -> Objects.nonNull(chatRecord.getExtras()))
//                .filter(chatRecord -> Objects.nonNull(chatRecord.getType()) && StringUtils.isNotBlank(chatRecord.getFromUserId()))
//                .filter(chatRecord -> chatRecord.getType().startsWith("1") || chatRecord.getType().startsWith("2"))
//                .filter(chatRecord -> {
//                    JSONObject jsonObject = JSON.parseObject(chatRecord.getExtras());
//                    if(Objects.nonNull(jsonObject) && jsonObject.containsKey("fromName")){
//                        return false;
//                    }else {
//                        return true;
//                    }
//                })
//                .peek(chatRecord -> {
//
//                    JSONObject jsonObject = JSON.parseObject(chatRecord.getExtras());
//                    long userId = Long.parseLong(chatRecord.getFromUserId());
//                    UsersVO userInfo = userList.get(userId);
//                    if (!userList.containsKey(userId)) {
//                        userInfo = userCenterService.getUserInfoById(userId).getData();
//                        if (Objects.isNull(userInfo)) {
//                            userInfo = new UsersVO();
//                        }
//                        userList.put(userId, userInfo);
//
//                    }
//                    System.out.println("修改前 extra = " + chatRecord.getExtras());
//                    if (Objects.nonNull(userInfo.getId()) && Objects.nonNull(jsonObject) && !jsonObject.containsKey("fromName")) {
//                        jsonObject.put("fromName", userInfo.getName());
//                        jsonObject.put("fromAvatar", userInfo.getAvatarUrl());
//                        chatRecord.setExtras(JSON.toJSONString(jsonObject));
//                    }
//                    System.out.println("修改后 extra = " + chatRecord.getExtras());
//                })
//                .collect(Collectors.toList());
//
//        int pageSize = 100;
//        int size = all.size();
//        int page = (int) Math.ceil((double) size / (double) pageSize);
//        long start = System.currentTimeMillis();
//        for (int i = 0; i < page; i++) {
//
//            List<TzChatRecord> temp = all.stream()
//                    .skip(pageSize * i)
//                    .limit(pageSize).collect(Collectors.toList());
//            messageService.batchUpdateByPrimaryKeySelective(temp);
//            long time = System.currentTimeMillis() - start;
//            System.out.println("需要修改总条数 size = " + all.size() + "总页码 = " + page + "执行到页数 = " + i + "耗时 = " + time/1000 +
//                    "预计还需要时间：" + (i != 0 ? time * (page / i) : 0)/1000);
//        }
//
//        return "success";
//    }
//
//
//    @GetMapping("/apiOne")
//    public String test() {
//        RequestDTO dto = new RequestDTO();
//        dto.setUserId("111");
//        dto.setDestId("999");
//        dto.setType("200");
//        dto.setMaxReadId("0");
//        List<TzChatRecord> tzChatRecords = tzChatRecordMapper.selectGroupChatRecord(dto);
//        List<TzChatRecord> tzChatRecords1 = tzChatRecordMapper.selectRoomChatRecord(dto);
//        System.out.println(tzChatRecords);
//        return "success";
//    }
//    @Autowired
//    private AuthClient authClient;
//
//    @GetMapping("/test2")
//    public String test2(String token) {
//        authClient.token(token);
//        return "success";
//    }
//
//
//}
